<template>
  <div class="echartsRight">
    <div class="echartsLeft_Title" @click="clickTitle">一户一宅债券（万）</div>
    <div class="echartsData" ref="echartsData">

    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import * as echarts from "echarts";
import "echarts-gl";

import { useMainStore } from "../../../../store/index"
const store = useMainStore()

const echartsData = ref()
let statusChart: any = null;

let series = [];
let option: any = {};
let pieDatas = [
  {
    "value": 75,
    "name": "下达金额"
  },
  {
    "value": 50,
    "name": "已支付金额"
  },
  {
    "value": 48,
    "name": "剩余金额"
  },
];

let maxRadius = 80,
  barWidth = 8,
  barGap = 15;
let showValue = true, showPercent = true;
let barColor = ["rgba(86,147,255,1)", "rgba(0, 255, 255, 1)", "rgba(255, 201, 95, 1)"];

const clickTitle = () => {
  store.showModelD = true

}

const setLabel = () => {
  pieDatas.map((item, i) => {
    series.push({
      type: 'pie',
      clockWise: false, //顺时加载
      hoverAnimation: false, //鼠标移入变大
      radius: [(maxRadius - i * (barGap + barWidth)) + '%', (maxRadius - (i + 1) * barWidth - i * barGap) + '%'],
      center: ["50%", "50%"],
      label: {
        show: false
      },
      itemStyle: {
        label: {
          show: false,
        },
        labelLine: {
          show: false
        },
        borderWidth: 5,
      },
      data: [{
        value: item.value,
        name: item.name,
        itemStyle: {
          color: barColor[i]
        }
      }, {
        value: 100 - item.value,
        name: '',
        itemStyle: {
          color: "transparent",
        },
        tooltip: {
          show: false
        },
        hoverAnimation: false
      }]
    })
    series.push({
      name: '',
      type: 'pie',
      silent: true,
      z: 0,
      clockWise: false, //顺时加载
      hoverAnimation: false, //鼠标移入变大
      radius: [(maxRadius - i * (barGap + barWidth)) + '%', (maxRadius - (i + 1) * barWidth - i * barGap) + '%'],
      center: ["50%", "50%"],
      label: {
        show: false
      },
      itemStyle: {
        label: {
          show: false,
        },
        labelLine: {
          show: false
        },
      },
      data: [{
        value: 1,
        itemStyle: {
          color: "rgba(27,36,62,0.6)",
        },
        tooltip: {
          show: false
        },
        hoverAnimation: false
      }]
    });
  })
}

const initChart = () => {
  statusChart = echarts.init(echartsData.value);
  option = {
    grid: {
      top: '3%',
      bottom: '54%',
      left: "8%",
      containLabel: false
    },
    // backgroundColor: '#000',
    tooltip: {
      show: false,
    },
    xAxis: [{
      show: false
    }],
    yAxis: [{
      type: 'category',
      inverse: true,
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        inside: true,
        textStyle: {
          color: "#fff",
          fontSize: 14,
        },
        margin: 195,
        show: true
      },
      data: pieDatas.map(x => x.value)
    }],
    legend: {
      show: true,
      top: '20%',
      right: '2%',
      icon: 'circle',
      itemWidth: 22,
      orient: 'vertical',
      itemGap: 20,
      // data: ['3G', '4G', '5G'],
      data: ["下达金额", "已支付金额", "剩余金额"],
      textStyle: {
        fontSize: 12,
        color: '#fff',
      },
      formatter: function (param) {
        return param
      }
    },
    series: series,
  };
  statusChart.setOption(option);
  window.addEventListener("resize", function () {
    statusChart.resize();
  });
}

onMounted(() => {
  setLabel()

  initChart()
})
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border - box;
}

.echartsRight {
  width: 450px;
  height: 100%;
  // border: 1px solid red;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  position: relative;

  .echartsLeft_Title {
    width: 250px;
    height: 48px;
    background-image: url("../../../../assets/lingshui/u154.png");
    background-size: 150% 160%;
    color: #FFFFFF;
    font-size: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
  }

  .echartsData {
    width: 100%;
    height: 210px;
    z-index: 99;
    // border: 1px solid red;
  }
}
</style>